/**
 * 
 */
package cn.crm.dao.impl;

import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import cn.crm.bean.Right;
import cn.crm.bean.User;
import cn.crm.dao.RightDao;
import cn.crm.service.UserService;

/**
 * @author Vi1___000
 *
 */
@Repository("rightDao")
public class RightDaoImpl extends HibernateDaoSupport implements RightDao {

	@Override
	public List<Right> getByParentID(String rid) {
		// TODO Auto-generated method stub
		if(rid==null || rid.equals("") || rid.isEmpty()){
			return super.getHibernateTemplate().find("from Right where parentid is null");
		}
		return super.getHibernateTemplate().find("from Right where parentid='"+rid+"'");
	}

	@Override
	public Right getByID(String id) {
		// TODO Auto-generated method stub
		List<Right> rlist = super.getHibernateTemplate().find("from Right where rid='"+id+"'");
		return rlist.size()>0?rlist.get(0):null;
	}

	@Override
	public boolean addRight(Right right) {
		// TODO Auto-generated method stub
		try {
			super.getHibernateTemplate().save(right);
			return true;
		} catch (DataAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
	}

	@Override
	public boolean updateRight(Right right) {
		// TODO Auto-generated method stub
		try {
			super.getHibernateTemplate().update(right);
			return true;
		} catch (DataAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
	}

	@Override
	public boolean delRight(Right right) {
		// TODO Auto-generated method stub
		try {
			super.getHibernateTemplate().delete(right);
			return true;
		} catch (DataAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
	}
	

}
